package com.dahua.simplefactory.version2;

import java.util.Scanner;

/**
 * @author sunhongguang
 * @create 2022-01-09-11:17
 */
public class Calculate {

    public static void main(String[] args) {
        try {
            Scanner scanner = new Scanner(System.in);
            System.out.println("请输入数字A： ");
            double numberA = scanner.nextDouble();
            System.out.println("请选择运算符号（+、-、*、/）: ");
            String operate = scanner.next();
            System.out.println("请输入数字B： ");
            double numberB = scanner.nextDouble();
            String result = null;
            switch (operate) {
                case "+":
                    result = String.valueOf(numberA + numberB);
                    break;
                case "-":
                    result = String.valueOf(numberA - numberB);
                    break;
                case "*":
                    result = String.valueOf(numberA * numberB);
                    break;
                case "/":
                    if(numberB !=0){
                        result = String.valueOf(numberA / numberB);
                    }else {
                        result = "除数不能为0！";
                    }
                    break;
            }
            System.out.println("结果是："+ result);
        } catch (Exception e) {
            System.out.println("你的输入有错，请检查后重新输入！");
        }
    }
}
